#include "t32.h"
#include "printk.h"

extern int main(void);
extern void prvHeapInit(unsigned int ucHeap, unsigned int ucHeapSize);

void system_init(void)
{
	trap_init();
	irq_init();
}

int c_main(unsigned int heap_base, unsigned int heap_size)
{
	unsigned int mie;
	unsigned int mip;
	unsigned int mstatus;
	unsigned int mtvec;

	printk("Entry c env\n");
	system_init();

	mie = read_csr(mie);
	mip = read_csr(mip);
	mstatus = read_csr(mstatus);
	mtvec = read_csr(mtvec);
	printk("mie = 0x%x, mip = 0x%x, mstatus = 0x%x\n",mie, mip, mstatus);
	printk("mtvec = 0x%x\n", mtvec);

	heap_base = (heap_base+0xf)&(~0xf);
	printk("heap_base = 0x%x, heap_size = 0x%x\n",heap_base, heap_size);
	prvHeapInit(heap_base, heap_size);

	return main();
}
